import 'package:app/core/theme/app_style.dart';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

typedef SetStatus = void Function(bool status);

class InfoStatusView extends StatefulWidget {
  final bool status;
  final String title;
  final String picUrl;
  final String subtitle;

  const InfoStatusView(
      {Key key,
      this.status = false,
      this.title,
      this.picUrl =
          'http://img.doutula.com/production/uploads/image/2021/07/14/20210714230834_ORzSnv.jpg',
      this.subtitle})
      : super(key: key);

  @override
  _InfoStatusViewState createState() => _InfoStatusViewState();
}

class _InfoStatusViewState extends State<InfoStatusView> {
  // final ValueNotifier<bool> _status = ValueNotifier<bool>(false);
  //
  // setStatus(bool status) {
  //   this._status.value = status;
  // }

  @override
  Widget build(BuildContext context) {
    return Container(
        alignment: Alignment.centerLeft,
        child: Row(
          mainAxisAlignment: MainAxisAlignment.start,
          children: [
            Padding(
              padding: EdgeInsets.all(8),
              child: ClipOval(
                child: CachedNetworkImage(
                    imageUrl: widget.picUrl,
                    placeholder: (context, url) => CircularProgressIndicator(),
                    errorWidget: (context, url, error) => ClipOval(
                            child: Image(
                          image: AssetImage('icons/cat.jpeg'),
                        ))),
              ),
            ),
            Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                Text(widget.title ?? ''),
                Row(
                  children: [
                    Padding(
                        padding: EdgeInsets.only(right: 3),
                        child: ClipOval(
                            child: Container(
                          width: 18.w,
                          height: 18.h,
                          color: widget.status ? Colors.green : Colors.red,
                        ))),
                    widget.status
                        ? Text(
                            "在线",
                            style: kBodyTextStyle,
                          )
                        : Text('已断开', style: kBodyTextStyle)
                  ],
                ),
              ],
            ),
          ],
        ));
  }
}
